package com.example.service.impl;

import com.example.mapper.master.StudentMapper;
import com.example.model.Student;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import javax.annotation.Resource;

/**
 * 测试同一个类事务调用是否生效
 */
@Slf4j
@Service
public class TransactionalService2 {

    @Resource
    private StudentMapper studentMapper;

    @Transactional(propagation=Propagation.REQUIRED)
    public void addStudent() {
        Student student = new Student();
        student.setCardId("1234");
        student.setName("tom");
        studentMapper.insert(student);

        // 模拟运行时异常
        int i = 10 / 0;
    }
}
